package com.jiuyue.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jiuyue.demo.Mapper.UserRepository;
import com.jiuyue.demo.entity.ExternalUser;
import com.jiuyue.demo.entity.User;
import com.jiuyue.demo.service.UserService;
@Controller
@RequestMapping("mongodb")
@ResponseBody
public class UserController {
	
	   @Autowired
	   private  UserRepository userRepository;
	   @Autowired
	   private UserService userService;
	   

	    @RequestMapping("/saveAll")
	    public String saveAllUser() {
	    	return userService.saveAllUser();
	    }
	    
	    

	    @RequestMapping("/saveLogAll")
	    public String saveLogAll() {
	    	return userService.saveLogUser();
	    }
	    
	    
	    @RequestMapping("/getOpenCount")
	    public int getOpenCount() {
	    	return userService.getOpenCount();
	    }
	    
	    
	    
	    
	    @RequestMapping("/getAll")
	    public  List<ExternalUser> getAll() {
	    	return userService.getAll();
	    }
	    
	    @RequestMapping("/getUserById/{id}")
	    public ExternalUser getUserById(@PathVariable(value = "id") String  id) {
	    	return userService.getUserById(id);
	    }
	    
	    /**
	     * 分页查询用户
	     * @param pageNum
	     * @param pageSize
	     * @return
	     */
	    @RequestMapping("/getUserBypage")
	    public  List<ExternalUser> getUserBypage(int pageNum,int pageSize) {
	    	return userService.getUserBypage(pageNum,pageSize);
	    }
	    	    	    
	    /**
	     * 精确查找 用户昵称
	     * @param keyword
	     * @return
	     */
	    @RequestMapping("/getUserByKeyWory")
	    public List<ExternalUser> getUserByKeyWory(String  userName) {
	    	return userService.getUserByName(userName);
	    }
	    
	    /**
	     * 模糊精确查找 用户昵称
	     * @param keyword
	     * @return
	     */
	    @RequestMapping("/getUserLikeName")
	    public  List<ExternalUser> getUserLikeName(String  userName) {
	    	return userService.getUserLikeName(userName);
	    }
	    
	    
	    /**
	     * 修改用户
	     * @param externalUser
	     * @return
	     */
	    @RequestMapping("/updateUser")
	    public  String updateUser(ExternalUser externalUser) {
	    	return userService.updateUser(externalUser);
	    }
	    
	    
	    /**
	     * 根据id删除
	     * @param externalUser
	     * @return
	     */
	    @RequestMapping("/deleteUserById")
	    public  String deleteUserById(String id) {
	    	return userService.deleteUserById(id);
	    }
	    
	
	

}
